package DevCode.Servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DevCode.Excepcion.DAOExcepcion;
import DevCode.Modelo.Idea;
import DevCode.Negocio.GestionIdea;


/**
 * Servlet implementation class BuscarIdeaServlet
 */
@WebServlet("/BuscarIdeaServlet")
public class BuscarIdeaFilterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuscarIdeaFilterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
			
		String IDvtitulo = request.getParameter("txtbusqueda");
		String IDvestado = request.getParameter("Cboestado");			
		int busqueda;
			if(IDvtitulo.equals("")){
				busqueda=1;
			}else{
				busqueda=0;
			}
		GestionIdea negocio = new GestionIdea();
		try {
			Collection<Idea> listaFilter = negocio.buscarFilterIdea(IDvtitulo, IDvestado, busqueda);
			//request.setAttribute("USvnombresb", USvnombres);
			//request.setAttribute("CFicodigob", CFicodigo);
			request.setAttribute("BUSQUEDA_IDEAFILTER", listaFilter);
			RequestDispatcher rd = request.getRequestDispatcher("Buscar_Idea.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
			rd.forward(request, response);
		}
		
	}

}
